// main.cpp

#define GL3_PROTOTYPES

// Include the vector and matrix utilities from the textbook, as well as some
// macro definitions.
#include "Angel.h"

#ifdef __APPLE__
#  include <OpenGL/gl3.h>
#endif

#include <stdio.h>
#include <fstream>
#include <iostream>
#include <string>
#include <boost/algorithm/string.hpp>
#include <vector>

#include "DebugHelper.h"
#include "ColorMapObject.h"
//#include "ColorContourWindow.h"
//#include "ColorContourWindow.h"

// A global constant for the number of points that will be in our object.
const int NumPoints = 21600 * 6;
using namespace std;
using namespace boost;
using namespace Voltron;



// USAGE
//		colorcontour

// globals
GLuint shaderprogram;
//ColorContourModel *ccm;
ColorMapObject *colormapobj;

//----------------------------------------------------------------------------
void init()
{
		
    vec3 tempPosVertices[] = {
        vec3(-0.5, -0.5, 0.0),
        vec3(0.5, -0.5, 0.0),
        vec3(0.5, 0.5, 0.0),
        vec3(-0.5, -0.5, 0.0),
        vec3(0.5, 0.5, 0.0),
        vec3(-0.5, 0.5, 0.0)
    };

    vec3 tempColorVertices[] = {
        vec3(1.0, 1.0, 0.0),
        vec3(0.0, 1.0, 0.0),
        vec3(1.0, 0.0, 1.0),
        vec3(1.0, 0.0, 1.0),
        vec3(0.0, 1.0, 0.0),
        vec3(1.0, 1.0, 0.0)
	};

	shaderprogram = InitShader("vshader32.glsl", "fshader32.glsl");
	
	colormapobj = new ColorMapObject(6,tempPosVertices,tempColorVertices,shaderprogram);
	//ccm = new	ColorContourModel("salinity.txt");
	//ccm.loadModel();

	//ccm->_colormapobj->initBuffers(shaderprogram);
	//ccm->_contourobj->initBuffers(shaderprogram);
    glClearColor(0.0, 1.0, 1.0, 1.0);
}



//----------------------------------------------------------------------------
void display(void)
{
    // clear the window
    glClear(GL_COLOR_BUFFER_BIT);

    // Draw the points.  The parameters to the function are: the mode, the first
    // index, and the count.
    //glDrawArrays(GL_TRIANGLES, 0, NumPoints);

	//ccm->render();
	// which just calls ccm->_colormaponj->render();
	// and              ccm->_counteronj->render();
	
	colormapobj->render();
	
    glFlush();
    glutSwapBuffers();
}

//----------------------------------------------------------------------------
void keyboard(unsigned char key, int x, int y)
{
    switch (key) {

    // Quit when ESC is pressed
    case 27:
        exit(EXIT_SUCCESS);
        break;
    }
}


int main (int argc, char *argv[])
{
	DEBUG_PRINT("main (int argc, char *argv[])\n");
	DEBUG_PRINT("argc=%d\n",argc);

	glutInit(&argc,argv);

	glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
	glutInitContextVersion(3,2);
	glutInitContextFlags(GLUT_FORWARD_COMPATIBLE);

	glutInitWindowSize(512,512);
	glutInitWindowPosition(500,300);
	glutCreateWindow("ColorContour");

	glewExperimental = GL_TRUE;
	glewInit();
	
	init();
	
	
	glutKeyboardFunc(keyboard);
	glutDisplayFunc(display);
	glutMainLoop();

	return 0;
}
